<template>
  <div class="generalWrap">
    <!-- 全局属性 -->
    <AttrCfg
      @filedChange="filedChange"
      :form="$store.state.formJson.formObj.GENERAL.attrForm"
      type="GENERAL"
      :filedList="$store.state.formJson.formObj['GENERAL'].filedList"
    ></AttrCfg>
    <!-- 字段配置 -->
    <FiledCfg type="GENERAL" :dataSource="$store.state.formJson.formObj.GENERAL.filedList"></FiledCfg>
  </div>
</template>

<script>
export default {
  data() {
    return {
      entFiledsList: [], // 企业表字段列表
      tempObj: {} // 选中表对象
    }
  },
  components: {
    AttrCfg: () => import('@/views/businessAssembly/jsonComponent/base/attrCfg.vue'),
    FiledCfg: () => import('@/views/businessAssembly/jsonComponent/base/filedCfg.vue')
  },
  mounted() {
    if (this.$store.state.formJson.listData?.length) {
      this.$store.state.formJson.listData.forEach(v => {
        this.tempObj[v.title] = v.title
      })
    }
  },
  methods: {
    // 字段改变
    filedChange(list, type, tableName) {
      if (type) {
        let listCopy = list.map(item => {
          return {
            b: item.fieldname,
            mapping: '',
            hidden: 'false',
            describe: item.comments
          }
        })
        if (listCopy?.length) {
          listCopy.forEach(v => {
            let temp = tableName + '#' + v.b
            if (temp in this.tempObj) {
              v.t = temp
            }
          })
        }
        this.$store.state.formJson.formObj.GENERAL.filedList = listCopy
      } else {
        let arry = []
        if (list?.length) {
          arry = list.map(item => {
            return {
              title: `${item.fieldname} - ${item.comments}`,
              value: item.fieldname
            }
          })
        }
        this.entFiledsList = arry
      }
    }
  }
}
</script>

<style lang="less" scoped>
.generalWrap {
  margin-top: 20px;
  height: 600px;
  overflow-y: auto;
}
</style>
